//
//  YCHouseServiceDetailViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/6.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  住宿服务详情

#import "YCHouseServiceDetailViewController.h"
#import "PreviewPhotoViewController.h"
#import "YCServiceButton.h"

@interface YCHouseServiceDetailViewController ()<SDCycleScrollViewDelegate>

/** 轮播  */
@property (nonatomic, weak) SDCycleScrollView *cycleScrollView;
/** 房间类型  */
@property (nonatomic, weak) UILabel *houseTypeLabel;
/** 价格  */
@property (nonatomic, weak) UILabel *costLabel;

@end

@implementation YCHouseServiceDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self yc_addBackBarButtonItem];
    self.navigationItem.title = @"详情";
    [self makeView];
}
- (void)makeView
{
    
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, 202) delegate:self placeholderImage:[UIImage yc_placeHolderImageForSize:CGSizeMake(kScreenWidth, 202)]];
    cycleScrollView.imageURLStringsGroup = @[@"http://img1.3lian.com/2015/w7/98/d/22.jpg",
                                               @"http://img1.3lian.com/2015/w7/90/d/5.jpg",
                                               @"http://img1.3lian.com/2015/w7/90/d/1.jpg",
                                               @"http://pic37.nipic.com/20140209/8821914_163234218136_2.jpg",
                                               @"http://pic39.nipic.com/20140226/18071023_162553457000_2.jpg",
                                               @"http://imgsrc.baidu.com/forum/pic/item/645b8701a18b87d6e716e197070828381e30fdae.jpg"];//网络图片链接数组
    cycleScrollView.delegate = self;
    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    cycleScrollView.pageDotColor = [UIColor yc_colorWithUInt:0xffffff alpha:0.5];
    cycleScrollView.currentPageDotColor = [UIColor yc_colorWithUInt:0xffffff];
    cycleScrollView.pageControlDotSize = CGSizeMake(12, 12);
    cycleScrollView.hidesForSinglePage = YES;
    cycleScrollView.autoScrollTimeInterval = 2.0;//2s自动轮播
    
    [self.view addSubview:cycleScrollView];
    self.cycleScrollView = cycleScrollView;
    
    
    UILabel *houseTypeLabel = [[UILabel alloc] init];
    houseTypeLabel.font = [UIFont systemFontOfSize:15];
    houseTypeLabel.textColor = [UIColor darkGrayColor];
    houseTypeLabel.text = @"普通房间";
    [self.view addSubview:houseTypeLabel];
    self.houseTypeLabel = houseTypeLabel;
    
    // 价格
    UILabel *costLabel = [[UILabel alloc] init];
    costLabel.font = [UIFont systemFontOfSize:15];
    costLabel.textColor = [UIColor redColor];
    costLabel.text = @"¥158";
    [self.view addSubview:costLabel];
    self.costLabel = costLabel;
    
    // 拨打客服电话
    YCServiceButton *callServiceButton = [YCServiceButton buttonWithType:UIButtonTypeCustom];
    [callServiceButton setImage:[UIImage imageNamed:@"shopCover_mobilePhone"] forState:UIControlStateNormal];
    callServiceButton.backgroundColor = [UIColor yc_colorWithRed:86 Green:200 Blue:14];
    [callServiceButton setTitle:@"拨打订房电话" forState:UIControlStateNormal];
    [callServiceButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [callServiceButton addTarget:self action:@selector(callServiceBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:callServiceButton];
    
    [cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
        make.height.equalTo(cycleScrollView.mas_width);
    }];
    
    [houseTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(cycleScrollView.mas_bottom).offset(20);
        make.left.equalTo(cycleScrollView);
    }];
    
    [costLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(houseTypeLabel.mas_right).offset(10);
        make.top.equalTo(houseTypeLabel);
    }];
    
   
    
    [callServiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-45);
        make.centerX.equalTo(self.view);
        make.width.equalTo(@150);//284px
        make.height.equalTo(@35);
    }];
    
}

#pragma mark - 点击事件
- (void)callServiceBtnClick:(UIButton *)button
{
    YCLogFunc
    LXActionSheet *actionSheet = [[LXActionSheet alloc] initWithCancelButtonTitle:@"取消" otherButtonTitlesArray:@[@"拔打 0871-68120277"]];
    UIButton *callButton =[actionSheet buttonAtIndex:1];
    callButton.titleLabel.font = [UIFont systemFontOfSize:17];
    [callButton setTitleColor:[UIColor yc_colorWithUInt:0x00b4ff] forState:UIControlStateNormal];
    [actionSheet showInView:self.view mask:YES maskColor:[UIColor colorWithWhite:0.3 alpha:1]  click:^(NSUInteger index, LXActionSheet *sheet) {
        if (index == 1) {
            if ([@"tel://087168120277" yc_canOpenURL]) {
                [@"tel://087168120277" yc_openURL];
            }
        }
    } cancel:^(NSUInteger index, LXActionSheet *sheet) {
        
    }];
}

#pragma mark - <SDCycleScrollViewDelegate>
/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSMutableArray *imagesArray = (NSMutableArray *)cycleScrollView.imageURLStringsGroup;
    //预览图片
    PreviewPhotoViewController *vc = [[PreviewPhotoViewController alloc] initWithImages:imagesArray displayIndex:index rightBarButtonItemTitle:@"" clickBlock:^(PreviewPhotoViewController *viewController, NSMutableArray *images, NSUInteger currentIndex) {
        YCLog(@"%@，%zd",images,currentIndex);
    }];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
